#include "gamecontroller.h"
#include <QDebug>
#include <QSound>

GameController *GameController::gameController = nullptr;
GameController::GameController()
    :mainScene(nullptr)
    ,levelScene(nullptr)
    ,gameScene(nullptr)
{

}

GameController::~GameController()
{

}

GameController* GameController::getInstance()
{
    if (gameController == nullptr)
    {
       gameController = new GameController();
    }
    return gameController;
}

void GameController::initMainScene(Mainscene *mainScene)
{
        this->mainScene = mainScene;
}

void GameController::showMainScene()
{

    if (mainScene != nullptr)
    {
        levelSceneGeometryInitialized = false;
        mainScene->show();
    }
}

void GameController::hideMinaScene()
{
    if (mainScene != nullptr)
    {
       mainScene->hide();
    }
}

void GameController::showLevelScene()
{
    if (levelScene == nullptr)
    {
        levelScene = new LevelScene();
    }
    if (!levelSceneGeometryInitialized)
    {
        levelScene->setGeometry(mainScene->geometry());
        levelSceneGeometryInitialized = true;
    }
    levelScene->show();
}

void GameController::hideLevelScene()
{
    if (levelScene != nullptr)
    {
        levelScene->hide();
    }
     mainScene->setGeometry(levelScene->geometry());
}

void GameController::showGameScene(int level)
{
    if (gameScene == nullptr)
    {
        gameScene = new GameScene(level);
    }
    gameScene->setGeometry(levelScene->geometry());
    gameScene->show();
}

void GameController::hideGameScene()
{
    if (gameScene != nullptr)
    {
        gameScene->hide();
    }
}

void GameController::deleteGameScene()
{
    if (gameScene != nullptr)
    {
        levelScene->setGeometry(gameScene->geometry());
        delete gameScene;
    }

    gameScene = nullptr;
}



void GameController::playStartSound()
{
    QSound::play(SOUND_TAP_BUTTON);
}

void GameController::playBackSound()
{
    QSound::play(SOUND_BACK_BUTTON);
}

void GameController::playFlipCoinSound()
{
    QSound::play(SOUND_COIN_FLIP);
}

void GameController::playWinSound()
{
    QSound::play(SOUND_LEVEL_WIN);
}
